<?php
// +----------------------------------------------------------------------
// | Copyright (c) 2004-2015 All rights reserved.
// +----------------------------------------------------------------------
// | Author: 张盛翔
// +----------------------------------------------------------------------
// | QQ：1213857382
// +----------------------------------------------------------------------
// | Module Discript: 后端接口底层模块
// +----------------------------------------------------------------------
namespace Rest\Controller;
use Think\Controller\RestController;
Class BaseController extends RestController {
	// 消息处理函数
	protected $allowMethod = array('get','post','put','delete'); // REST允许的请求类型列表
	protected $defaultMethod = get; // REST默认请求类型
	protected $allowType = array('html','xml','json'); // REST允许请求的资源类型列表
	protected $defaultType = json; // REST默认的资源类型
	protected $allowOutputType = array( 'xml' => 'application/xml', 'json' => 'application/json','html' => 'text/html',); // REST允许输出的资源类型列表

	public function respond($res,$data,$type)
	{
		// 消息体处理
		if ($res == "success") {
			$response_data['res'] = 1;
			$response_data['data'] = $data;
		}elseif ($res == "error") {
			$response_data['res'] = 0;
			$response_data['data'] = $data;
		}else{
			$response_data['res'] = 0;
			$response_data['data'] = "Program parameter error";
		}
		// 消息体类型判断
		if ($type == 'html'){
			$this->response($response_data,'json');
		}elseif($type == 'xml'){
			$this->response($response_data,'json');
		}elseif($type == 'json'){
			$this->response($response_data,'json');
		}
	}

	// 登录检测
	public function checklogin()
	{
		if ($_SESSION['account']) {
			// 已经登录
		}else{
			// 未登录
			$data['errorcode'] = "未登录";
			$this -> respond("error",$data,$this->_type);
		}
	}

 }